package com.zeng.jiudian.servlet.online;

import com.alibaba.fastjson.JSONObject;
import com.zeng.jiudian.bean.OnlineModel;
import com.zeng.jiudian.service.OnlineService;
import com.zeng.jiudian.service.impl.OnlineServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author JJ_yo
 * @Date 2020/7/31 - 9:43
 */
@WebServlet("/back/online/edit")
public class OnlineEditServlet extends HttpServlet
{
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        String idString = req.getParameter("id");
        int id = (idString == null || "".equals(idString) ? 0 : Integer.parseInt(idString));

        String name = req.getParameter("name");
        String phone = req.getParameter("phone");
        String startDate = req.getParameter("startDate");
        String endDate = req.getParameter("endDate");
        String roomType = req.getParameter("roomType");
        String idea = req.getParameter("idea");

        OnlineModel onlineModel = new OnlineModel();
        onlineModel.setId(id);
        onlineModel.setName(name);
        onlineModel.setPhone(phone);
        onlineModel.setStartdate(startDate);
        onlineModel.setEnddate(endDate);
        onlineModel.setRoomtype(roomType);
        onlineModel.setIdea(idea);

        OnlineService onlineService = new OnlineServiceImpl();
        int count = onlineService.update(onlineModel);

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("count", count);
        resp.getWriter().println(jsonObject);
    }
}
